#include "Arrow.h"


CArrow::CArrow(CRange* Shooter, CUnit* Target, State Newstate)
{
	SetSize(5);
	this->SetDamage(Shooter->GetDamage());
	this->Direction = (Target->GetPos() - Shooter->GetPos());
	this->SetSpeed(20);
	this->SetPos(Shooter->GetPos());
	this->SetActive(true);
	SetMaxHealth(1);
	SetHealth(GetMaxHealth());
	state = Newstate;
}


CArrow::~CArrow(void)
{
}


void CArrow::Render(void)
{
	glDisable(GL_BLEND);
	if(state == ARROW_DAMAGE)
		glColor4f(0.0f, 0.0f, 1.0f, 0.25f);
	else if(state == ARROW_HEAL)
		glColor4f(0.0f, 1.0f, 1.0f, 0.25f);
	glPushMatrix();
	glTranslatef(GetPos().x, GetPos().y, GetPos().z);
	glScalef(GetSize(), GetSize(), 1);
	glutSolidSphere(1, 20, 20);
	glPopMatrix();
}
void CArrow::Update(float dt)
{
	this->SetPos(this->GetPos() + Direction.Normalized()*this->GetSpeed());
}
void CArrow::UnitInteraction(CUnit* go_Unit)
{
	if(this->GetTeam() != go_Unit->GetTeam())
	{
		if(CUnit* test = dynamic_cast<CUnit*>(go_Unit) ) 
		{ 
			if (CArrow* test = dynamic_cast<CArrow*>(go_Unit))
			{
				return;
			}
			else if((go_Unit->GetPos() -this->GetPos()).Length() <= go_Unit->GetSize() + this->GetSize())
			{
				this->SetActive(false);
				go_Unit->DealDamageTo(this);
			}
		}
	}
	else if(this->GetTeam() == go_Unit->GetTeam())
	{
		if(CMelee* Melee = dynamic_cast<CMelee*>(go_Unit) ) 
		{ 
			if(( Melee->GetPos() -this->GetPos()).Length() <=  Melee->GetSize() + this->GetSize())
			{
				this->SetActive(false);
				 Melee->HealTo(this);
			}
		}
	}
}

void CArrow::DealDamageTo(CUnit*)
{

}

void CArrow::PrintState(int x, int y, float r, float g, float b, char* str)
{

}
